The goal of this tutorial is to explore how to fit hidden Markov models
(HMMs) to movement data. To do so, we will use the R package momentuHMM,
which was developed by Brett McClintock and Théo Michelot.
This package builds on a slightly older package,
moveHMM, that was developed by Théo Michelot, Roland Langrock, and
Toby Patterson, see associated paper:
https://besjournals.onlinelibrary.wiley.com/doi/full/10.1111/2041-210X.12578.
momentuHMM has new features such as allowing for more data streams,
inclusion of covariates as raster layers, and much more,
see associated paper:
https://besjournals.onlinelibrary.wiley.com/doi/abs/10.1111/2041-210X.12995.
The primary learning objectives in this first tutorial are to:
momentuHMMWe also include an Extra section where you can explore:
First, let’s load the packages that we will need to complete the analyses. Of course you need to have them installed first.
library(momentuHMM) # Package for fitting HMMs, builds on moveHMM
library(raster) # For importing and extracting raster spatial covariates
library(dplyr) # data management
library(tidyr) # data management
library(terra)
library(tidyterra)
library(ggplot2) # plot the data
library(ggspatial) # plot the data
library(lubridate) # transform numeric vectors to POSIXct objects.
library(sf) # spatial data processing
library(kableExtra) # produce visually appealing tables
library(geosphere) # Needed to calculate step lengths from lat/lon locations - just need it installedWhile the raster package is being phased out in favour of the new terra package, momentuHMM still relies on the raster package to extract covariates. Therefore, for this tutorial we will still use raster, but we also use terra at times as it is most up-to-date package for rasters.
Make sure to set working directory to “2_Movement_Tutorial” folder of the HMM workshop folder.
We will need the functions in the following file utility_functions.R.
We will analyze a dataset containing movement tracks of three narwhals tagged with Fastloc-GPS tags. The dataset was provided by Dr. Marianne Marcoux (Fisheries and Oceans, Canada). For simplicity, we only examine the fastloc-GPS data from one week in August 2017.